package com.iptv.grape.event.imp;

import com.google.gson.Gson;
import com.iptv.grape.BaseActivity;
import com.iptv.grape.bu.GrapeContext;
import com.iptv.grape.domain.AssetPlayData;
import com.iptv.grape.event.JSRequest;
import com.iptv.grape.event.msg.PlayRecordByIDMsg;
import com.iptv.grape.event.proc.IWebViewMessageProc;
import com.iptv.grape.util.AppLog;
import com.iptv.grape.video.XMediaPlayer;

// 根据资产ID来返回播放记录
public class PlayRecordByIDProc implements IWebViewMessageProc {

    private PlayRecordByIDMsg argsData;
    @Override
    public void init(JSRequest jsRequest) {
        argsData = new Gson().fromJson(jsRequest.getJson(), PlayRecordByIDMsg.class);
    }

    @Override
    public String procMessage(BaseActivity baseActivity, XMediaPlayer mediaPlayer) {
        AssetPlayData assetPlayData = GrapeContext.curGrapeContext().getAssetPlayDataList().find(argsData.getData());
        if(assetPlayData == null){
            AppLog.getCurLog().out("PlayRecordByIDProc = {}");
            return "{}";
        }
        else {
            String json = new com.google.gson.Gson().toJson(assetPlayData.toMsg());
            //AppLog.getCurLog().out("PlayRecordByIDProc = " + json);
            return  json;
        }
    }
}
